<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分类管理</title>
<script src="../js/jquery1.9.1.js" type="text/javascript"></script>
<script src="../js/jquery.pager.js" type="text/javascript"></script>
<script src="../js/iframeAuto.js" type="text/javascript"></script>
<link href="../js/Pager.css" rel="stylesheet" type="text/css" />
<link href="../styles/edas_back.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div id="mainContainer" style="Margin-Right: auto; Margin-Left: auto;"
		align="left">

		<table id="data_table_id" class="didiao">
			<tr id="title_id">
				<td width="220px" style="border-top: 0px;">最后更新时间</td>
				<td width="120px" style="border-top: 0px;">名称</td>
				<td width="120px" style="border-top: 0px;">操作</td>
			</tr>
			<tr id="start_id">
			</tr>
		</table>

		<br> <br> <br>
		<div id="pager"></div>

		<table id="table_model_id" style="display: none">
			<tr id="tr_model_id">
				<td width="120px" id="room_start_time"></td>
				<td width="120px" id="per_name_id"></td>
				<td width="120px"><a id="edit_id" href="#" title="编辑"><img
						border="0px" src="../images/btn_edit.png" /></a> <a id="del_id"
					href="#" title="删除"><img border="0px"
						src="../images/btn_delete.png" /></a></td>
			</tr>
		</table>

	</div>

	<script>
		$(function(){
			init(1);
		});
		//默认加载  
		function init(pagenumber) {
			
		jQuery
					.ajax({
						type : 'Get',
						contentType : 'application/json',
						url : '../category/pageList.do',
						data : {
							currPage : pagenumber
						},
						dataType : 'json',
						success : function(data) {
							if (data.result) {
								$("#pager").pager({
									pagenumber : pagenumber,
									pagecount : data.obj.totalPage,
									buttonClickCallback : PageClick
								});

								//删除表格原先数据
								$('#data_table_id tr')
										.each(
												function() {
													if ($(this).attr("id") != "start_id"
															&& $(this).attr(
																	"id") != "title_id") {
														$(this).remove();
													}
												});

								try {
									//为表格设置数据
									var categoryList = data.obj.categoryList;
									for ( var i in categoryList) {
										var htm1 = $('#tr_model_id').html();
										var newTr1 = "<tr>" + htm1 + "</tr>";
										var newTr1Obj = $('#start_id').before(
												newTr1).prev();
										var name = categoryList[i].name;
										newTr1Obj
												.find("#room_start_time")
												.html(
														categoryList[i].updateDate);
										newTr1Obj.find("#per_name_id").html(
												categoryList[i].name);
										
										newTr1Obj.find("#del_id").click(function(){
											if(!confirm("确定要彻底删除该用户！")){
												return;				          				
											}
											jQuery.ajax({
					          					type : 'Get',
					          					contentType : 'application/json',
					          					url : '../category/del.do',
					          					data : {
					          						id : categoryList[i].id
					          					},
					          					dataType : 'json',
					          					success : function(data) {
					          						if (data.result) {
					          							alert('删除数据成功');
					        							init(1);
					          						}else{
					          							alert(data.errorMsg);
					          						}
					          					},
					          					error:function(data){
					          						alert("error");
					          					}
											});
										});
									}

								} catch (e) {
									alert(e);
								}
								//调整iframe高度
								autoIframe();
							}

							else {
								alert(data.errorMsg);
							}
						},
						error : function(data) {
							alert("error");
						}
					});
		}

		//回调函数  
		PageClick = function(pageclickednumber) {
			init(pageclickednumber);
		}
	</script>

</body>
</html>